//
//  stats_mcast_client.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013-2014 Razvan Coca (razvan dot coca at  gmail dot com)
// This is mostly generated code. Generator is distributed under GPL. Edit it to suit your needs.
// 


#ifndef STATS_MCAST_CLIENT_HPP
#define STATS_MCAST_CLIENT_HPP
#include <boost/thread.hpp>
#include "components/service/mcast_client_process.hpp"
#include "components/protocol/stats_client_processor.hpp"
class shutdown_exception:public std::runtime_error
{
public:
    shutdown_exception(const std::string& arg):std::runtime_error(arg){}
};
class stats_mcast_client:private boost::noncopyable
{


    ba::io_service& ios_;
    std::string name_;`
    boost::shared_ptr<components::service::mcast_client_process> mcast_client_process_;
    bt::millisec flight_base_;
    bt::millisec flight_increment_;
    int nitems_;
    ba::deadline_timer timer_;
    bool worker_is_done_;
    boost::mutex mutex_;
    boost::condition_variable condition_;
    boost::shared_ptr<boost::asio::io_service::work> work_;
    boost::thread thread_;
    components::protocol::stats_client_processor processor_fsm_;
    stats_message_client_processor message_processor_;
    std::vector<stats_message_t> replies_;
    void thread_func();

public:
    void handle_service_done   (bs::error_code const& ec,const crypto_error& eec);
    stats_mcast_client(ba::io_service& ios, udp_endpoint_t& local_if, udp_endpoint_t& mgroup, int ttl,
                       crypto_buf_t& iv, crypto_buf_t& key,
                       bt::millisec flight_base, bt::millisec flight_increment, int nitems,
                       const std::string &cluster, const std::string &node);

    bool query(stats_message_t & message);
    std::vector<stats_message_t> get_results();
    void stop(){ios_.post([](){throw shutdown_exception("stop");});thread_.join();}
};

#endif // STATS_MCAST_CLIENT_HPP
